package cn.edu.huas.shopping.dao;

import cn.edu.huas.shopping.exception.DaoException;
import cn.edu.huas.shopping.pojo.Banner;
import cn.edu.huas.shopping.utils.DBUtils;

import java.util.ArrayList;
import java.util.List;

public class BannerDaoImpl implements BannerDao{
    @Override
    public List<Banner> queryBanner() throws DaoException {
        String sql="SELECT id,pic,`ORDER`,pid FROM t_banner WHERE online='0' ORDER BY 'order'";
        return DBUtils.query(sql,rs -> {
            List<Banner> banners=new ArrayList<>();
            while (rs.next()){
                Banner b=new Banner();
                b.setId(rs.getInt("id"));
                b.setPid(rs.getInt("pid"));
                b.setOrder(rs.getInt("order"));
                b.setPic(rs.getString("pic"));
                banners.add(b);
            }
            return banners;
        }) ;
    }
}
